package m.jclecai.com.pop;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import m.jclecai.com.R;

/**
 * Created by andy on 2017/7/7.
 */

public class GuideMenuPopupWindow extends BasePopupWindow {

    private LinearLayout mContentView;

    public GuideMenuPopupWindow(Context context) {
        super(context);
        init();
    }

    private void init() {
        //这里的话，我们做一个初始化的一个操作；
        setFocusable(true);
        setOutsideTouchable(true);
        setContentView(R.layout.popup_window_linearlayout);

        mContentView =(LinearLayout) mView.findViewById(R.id.ll_item);

    }

    //添加一个条目；
    public void addItem(String string,View.OnClickListener onClickListener){
        View view = View.inflate(getContext(), R.layout.item_pop_window_guide, null);

        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        }else{
            layoutParams.width= ViewGroup.LayoutParams.WRAP_CONTENT;
            layoutParams.height= ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        view.setLayoutParams(layoutParams);

        TextView textView = (TextView) view.findViewById(R.id.tv_item);
        textView.setText(string);

        if (onClickListener != null) {
            textView.setOnClickListener(onClickListener);
        }
        mContentView.addView(view);
    }

    public void setTitle(int position,String title){
        View view = mContentView.getChildAt(position);
        TextView textView = (TextView) view.findViewById(R.id.tv_item);
        textView.setText(title);
    }

    public void setItemClickListener(int position ,View.OnClickListener onClickListener){
        View view = mContentView.getChildAt(position);
        TextView textView = (TextView) view.findViewById(R.id.tv_item);
        textView.setOnClickListener(onClickListener);
    }

    @Override
    protected int setPopWindowAnimationStyle() {
        return R.style.AnimationPreview;
    }


    @Override
    protected boolean allowBackgroundTranslucent() {
        return false;
    }
}
